#include <iostream>
#include <string>
#include <list>
#include "Const.h"
#include "PlayerClass.h"
#include "SpaceClass.h"


using namespace std;







//class PlayerClass;

void mainMenu(bool &freeParking, bool &snakeEyes, bool &landOnGo,
              int &numPlayers, int &numHuman)
{
  int choice;
  int choice2;
  bool correct;

  //default settings
  freeParking = true;//get 500+extra for landing on free parking
  snakeEyes = true;//get $686 for rolling (one, one)
  landOnGo = true;//get $400 for landing on go

  cout << "Please select from the following menu" << endl;
  cout << "1. View Basic Rules\n2. Options Menu\n3. Play Game\nYour choice: ";

  do
  {
    correct = false;
    cin >> choice;
    if (choice != 1 && choice != 2 &&  choice != 3)
    {
      cout << "Invalid menu choice, try again:\n";
    }
    else
    {
      correct = true;
    }
  }while(!correct);
  
  if (choice == 1)
  {
    cout << "--------OBJECT--------" << endl;
    cout << "The goal is to become the wealthiest player through renting,";
    cout << "buying, and selling property\n";
    cout << "--------EQUIPMENT AND PREPARATION--------\n";
    cout << "There are between 2-8 players playing on a monopoly board of";
    cout << " 40 spaces containing properties, community chest, chance, jail";
    cout << " and taxes. Each player starts with $1500 \n";
    cout << "--------GAMEPLAY--------\n";
    cout << "Players take turns throwing dice and moving around the board.";
    cout << " Upon landing on properties, one may purchase the property or ";
    cout << "pay the owner rent. The game ends when all but one player ";
    cout << "goes bankrupt declaring the remaining player the winner.\n";
    mainMenu(freeParking, snakeEyes, landOnGo, numPlayers, numHuman);
  }
  else if (choice == 2)
  {
    cout << "Free Parking:\n1. Yes\n2. No" << endl;
    
    do 
    {
      correct = false;
      cout << "Your Choice: ";
      cin >> choice2;
      if (choice2 == 1)
      {
        correct = true;
        freeParking = true;
      }
      else if (choice2 == 2)
      {
        correct = true;
        freeParking = false;
      }
      else 
      {
        cout << "Invalid menu choice, try again:\n";
      }
    }while(!correct);

    
    cout << "Snake Eyes:\n1. Yes\n2. No" << endl;
    do
    {
      correct = false;
      cout << "Your Choice: ";
      cin >> choice2;
      if (choice2 == 1)
      {
        correct = true;
        snakeEyes = true;
      }
      else if (choice2 == 2)
      {
        correct = true;
        snakeEyes = false;
      }
      else 
      {
        cout << "Invalid menu choice, try again:\n";
      }
    }while (!correct);
    
    cout << "$400 for landing on go:\n1. Yes\n2. No" << endl;
    do
    {
      correct = false;
      cout << "Your Choice: ";
      cin >> choice2;
      if (choice2 == 1)
      {
        correct = true;
        landOnGo = true;
      }
      else if (choice2 == 2)
      {
        correct = true;
        landOnGo = false;
      }
      else 
      {
        cout << "Invalid menu choice, try again:\n";
      }
    }while(!correct);
    mainMenu(freeParking, snakeEyes, landOnGo, numPlayers, numHuman);
  }
  else if (choice == 3)
  {
    cout << "Enter the number of players (2-8): \n";
    cin >> numPlayers;
    while (numPlayers < 2 || numPlayers > 8)
    {
      cout << "Invalid choice, please choose between 2 to 8 players: ";
      cin >> numPlayers;
    }
    cout << "Of the " << numPlayers << ", how many are human?" << endl;
    cin >> numHuman;
    while (numHuman < 0 || numHuman > numPlayers)
    {
      cout << "Invalid choice, please enter the number of human players.\n";
      cin >> numHuman;
    }
  }
}





class BankClass
{
  private:
    int numHouses;
    int numHotels;
};

class DiceClass
{
  private: 
};
/*
class CardClass
{
  private:
    string message;
    int function;
  public:
    void payBank(int amount);//positive is you pay bank, negative recieve money
    void payPlayers(int amount);//positive: pay every player, negative receive
    void movePlayer(int location);//move player
    void payHouses(int numHouses, int numHotels);
    
};*/

void setPlayers(int numPlayers, int numHuman, list<PlayerClass> &playerList)
{
  PlayerClass player;

  for (int i = 0; i < numHuman; i++)
  {
    player = PlayerClass(i, true);
    playerList.push_back(player);
  }
  for (int i = numHuman; i < numPlayers; i++)
  {
    player = PlayerClass(i, false);
    playerList.push_back(player);
  }
}

class BoardClass
{
  private:
    int numSpaces;
  public:
    BoardClass()
    {
      numSpaces = BOARDSIZE;
    }
};



SpaceClass* setUpBoard(bool freeParking)
{
  SpaceClass* board;
  board = new SpaceClass [BOARDSIZE];

  board[go] = GoClass("GO");
  board[medAve] = EstateClass("Mediterranean Avenue", 60, purple, 2, 10, 30,
                             90, 160, 250, 50);
  board[commChest1] = CommChestClass();
  board[balticAve] = EstateClass("Baltic Avenue", 60, purple, 4, 20, 60, 180,
                             320, 450, 50);
  board[incomeTax] = IncomeTaxClass();
  board[readingRR] = RailRoadClass("Reading RailRoad");
  board[orientalAve] = EstateClass("Oriental Avenue", 100, skyBlue, 6, 30, 90,
                             270, 400, 550, 50);
  board[chance1] = ChanceClass();
  board[vermontAve] = EstateClass("Vermont Avenue", 100, skyBlue, 6, 30, 90,
                             270, 400, 550, 50);
  board[connAve] = EstateClass("Connecticut Avenue", 120, skyBlue, 8, 40, 
                             100, 300, 450, 600, 100);
  board[jail] = JailClass();
  board[stCharles] = EstateClass("St. Charles Avenue", 140, magenta, 10, 50,
                             150, 450, 625, 750, 100);
  board[electric] = UtilityClass("Electric Company");
  board[stateAve] = EstateClass("States Avenue", 140, magenta, 10, 50,
                             150, 450, 625, 750, 100);
  board[virginiaAve] = EstateClass("Virginia Avenue", 160, magenta, 12, 60,
                             180, 500, 700, 900, 100);
  board[pennRR] = RailRoadClass("Pennsylvania RailRoad");
  board[stJames] = EstateClass("St. James Place", 180, orange, 14, 70, 200,
                             550, 750, 950, 100);
  board[commChest2] = CommChestClass();
  board[tennesseeAve] = EstateClass("Tennessee Avenue", 180, orange, 14, 70,
                             200, 550, 750, 950, 100);
  board[nyAve] = EstateClass("New York Avenue", 200, orange, 16, 80, 220,
                             600, 800, 1000, 100);
  board[freeParking] = FreeParkingClass(freeParking);
  board[kentuckyAve] = EstateClass("Kentucky Avenue", 200, red, 18, 90, 250,
                             700, 875, 1050, 150);
  board[chance2] = ChanceClass();
  board[indianaAve] = EstateClass("Indiana Avenue", 200, red, 18, 90, 250,
                             700, 875, 1050, 150);
  board[illinoisAve] = EstateClass("Illinois Avenue", 220, red, 20, 100, 300,
                             750, 925, 1100, 150);
  board[boRR] = RailRoadClass("B & O RailRoad");
  board[atlanticAve] = EstateClass("Atlantic Avenue", 240, yellow, 22, 110,
                             330, 800, 975, 1150, 150);
  board[ventnorAve] = EstateClass("Ventnor Avenue", 240, yellow, 22, 110,
                             330, 800, 975, 1150, 150);
  board[waterWorks] = UtilityClass("Water Works");
  board[marvinGardens] = EstateClass("Marvin Gardens", 260, yellow, 24, 120,
                             360, 850, 1025, 1200, 150);
  board[goToJail] = GoToJailClass();
  board[pacificAve] = EstateClass("Pacific Avenue", 300, green, 26, 130, 390,
                             900, 1100, 1275, 200);
  board[northCarolinaAve] = EstateClass("North Carolina Avenue", 300, green, 
                             26, 130, 390, 900, 1100, 1275, 200);
  board[commChest3] = CommChestClass();
  board[pennAve] = EstateClass("Pennsylvania Avenue", 320, green, 28, 150,
                             450, 1000, 1200, 1400, 200);
  board[shortLineRR] = RailRoadClass("Short Line");
  board[chance3] = ChanceClass();
  board[parkPlace] = EstateClass("Park Place", 350, darkBlue, 35, 175, 500,
                             1100, 1300, 1500, 200);
  board[luxuryTax] = LuxuryTaxClass();
  board[boardWalk] = EstateClass("Board Walk", 400, darkBlue, 35, 200, 600,
                             1400, 1700, 2000, 200);

  return board;
}

enum CardType
{
  payMoney,//negative means recieve
  payPlayers,//negative means recieve
  advanceProperty,
  advanceUtility,
  advanceRR,
  advanceGO,
  advanceJail,
  houseTax,
  getOutOfJailFree,
  goBackThree,
};

class CardClass
{
  private:
    string message;
    int cardType;
  public:
    CardClass();
    CardClass(int typeOfCard, string messaging, int value);
};

CardClass::CardClass()
{
}

CardClass::CardClass(int typeOfCard, string messaging, int value)
{
  message = messaging;
  cardType = typeOfCard;
  
}

CardClass* makeCommChest(bool extra)
{
  CardClass* pile;
  pile = new CardClass[NUMCHANCECARDS];
  pile[0] = CardClass(advanceGO, "Advance to GO, collect $200", 0);
  pile[1] = CardClass(payMoney, "Bank error in your favor, collect $200", -200);
  pile[2] = CardClass(payMoney, "Dector's fee, pay $50", 50);
  pile[3] = CardClass(payMoney, "From sale of stock you get $45", -45);
  pile[4] = CardClass(advanceJail, "Go directly to jail, do not pass go", jail);
  pile[5] = CardClass(getOutOfJailFree, "Get out of jail free card", 0);
  pile[6] = CardClass(payMoney, "Income tax refund, collect $20", -20);
  pile[7] = CardClass(payMoney, "Life insureance matures, collect $100", -100);
  pile[8] = CardClass(payMoney, "Pay Hospitol $100", 100);
  pile[9] = CardClass(payMoney,"Pay School Tax of $150", 150);
  pile[10] = CardClass(payMoney, "Receive for Services $25", -25);
  pile[11] = CardClass(payMoney, "You won second prize in a beauty contest collect $10", -10);
  pile[12] = CardClass(payMoney,"You inherit $100", -100);
  pile[13] = CardClass(payMoney,"Xmas fund matures, receive $100", -100);
  pile[14] = CardClass(payPlayers, "Collect $50 from every player for opening night seats", -50);
  pile[15] = CardClass(houseTax, "You are assessed for street repairs, pay $40 per house and $115 per hotel", 0);
  return pile;

}

CardClass* makeChance(bool extra)
{
  CardClass* pile;
  pile = new CardClass[NUMCHANCECARDS];
  pile[0] = CardClass(advanceGO, "Advance to GO, collect $200", 0);
  pile[1] = CardClass(advanceProperty, "Advance to St. Charles Place", stCharles);
  pile[2] = CardClass(advanceProperty, "Advance to Boardwalk", boardWalk);
  pile[3] = CardClass(advanceProperty, "Advance to Illinois Avenue", illinoisAve);
  pile[4] = CardClass(advanceJail, "Go directly to jail, do not pass go", jail);
  pile[5] = CardClass(getOutOfJailFree, "Get out of jail free card", 0);
  pile[6] = CardClass(advanceRR, "Advance to the nearest railroad, if unknowned, you may but it from the bank. If owned, pay owner twice the rental", 0);
  pile[7] = CardClass(goBackThree, "Go Back Three Spaces", 0);
  pile[8] = CardClass(advanceUtility, "Advance to the nearest utility. If unowned, you may buy it. If owned, roll the dice and pay 10 times the amount thrown", 0);
  pile[9] = CardClass(payMoney, "Your building loan matures, collect $150", -150);
  pile[10] = CardClass(advanceProperty, "Take a trip to Reading Railroad", readingRR);
  pile[11] = CardClass(houseTax, "Make general repairs on all your propertires, for each house pay $25, for each hotel pay $100", 0);
  pile[12] = CardClass(payMoney, "Pay poor tax of $15", 15);
  pile[13] = CardClass(payMoney, "Bank pays you dividend of $50", -50);
  pile[14] = CardClass(payPlayers, "You have been elected chairman of the board. Pay each player $50", 50);
  pile[15] = CardClass(advanceRR, "Advance to the nearest railroad, if unknowned, you may but it from the bank. If owned, pay owner twice the rental", 0);
  
  return pile;
}

void printBoard(int ID, int location)
{
  if(location >= 20 && location < 30)
  {
    for(int i = 0; i < location - 20; i++) 
    {
      cout << " ";
    }
    cout << ID;
    for(int i = location - 20 + 1; i < 10; i++) 
    {
      cout << " ";
    }
    cout << endl;
    cout <<   " OOOOOOOOOO " << endl;
    for(int i = 0; i < 38; i++)
    {
      cout << " O        O " << endl;
    }
    cout <<   " OOOOOOOOOO " << endl;
    cout << endl;
  }
  
  if(location >= 10 && location < 20)
  {
    cout << endl;
    for(int i = 19; i > location; i--)
    {
      cout << endl;
    }
  //STILL IN PROGRESS!!
  
  }
}
      
    

